﻿using System.Drawing;

namespace PlusPlusPaint.Layers.VisualObjects
{
    /// <summary>
    /// Represents an ellipse on the screen, only the edge of which is visible.
    /// The dimensions of the ellipse must be equal to the dimensions of the
    /// containing layer.
    /// </summary>
    class EmptyEllipse : DynamicallyGeneratedVisualObject
    {
        #region properties
        protected override string ObjectTypeName
        {
            get
            {
                return "EmptyEllipse";
            }
        }
        #endregion

        #region constructors
        public EmptyEllipse()
        {

        }

        public EmptyEllipse(Point start, Point end)
        {
            SetBoxAround(start, end);
        }
        #endregion

        #region overrides

        public override bool PositionIsInHitbox(Point p)
        {
            Rectangle rect = this.ClientRectangle; // This is by-value!
            rect.Inflate(2*MaximumDistanceToRecogniseOnClick, 2*MaximumDistanceToRecogniseOnClick);
            if (!FilledEllipse.IsInEllipseBoundedBy(rect, p))
                return false;
            rect.Inflate(-4*MaximumDistanceToRecogniseOnClick, -4*MaximumDistanceToRecogniseOnClick);
            return !FilledEllipse.IsInEllipseBoundedBy(rect, p);
        }

        public override IVisualObject Clone()
        {
            EmptyEllipse copy = new EmptyEllipse(Location, Location + Size);
            copy.Colour = Colour;
            return copy;
        }

        public override void BurnOn(Image im)
        {
            using (Pen p = new Pen(this.Colour, this.BrushSize))
                Graphics.FromImage(im).DrawEllipse(p, this.ClientRectangle);
        }
        #endregion
    }
}
